/*    */ package com.zimbra.cs.datasource;
/*    */ 
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.cs.account.DataSource;
/*    */ import com.zimbra.cs.db.DbDataSource;
/*    */ import com.zimbra.cs.db.DbDataSource.DataSourceItem;
/*    */ import com.zimbra.cs.db.DbPop3Message;
/*    */ import java.util.Arrays;
/*    */ import java.util.Collection;
/*    */ import java.util.HashSet;
/*    */ import java.util.Map;
/*    */ import java.util.Set;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class PopMessage
/*    */   extends DataSourceMapping
/*    */ {
/*    */   public PopMessage(DataSource ds, DbDataSource.DataSourceItem dsi)
/*    */     throws ServiceException
/*    */   {
/* 33 */     super(ds, dsi);
/*    */   }
/*    */   
/*    */   public PopMessage(DataSource ds, int itemId) throws ServiceException {
/* 37 */     super(ds, itemId);
/*    */   }
/*    */   
/*    */   public PopMessage(DataSource ds, String uid) throws ServiceException {
/* 41 */     super(ds, uid);
/*    */   }
/*    */   
/*    */   public PopMessage(DataSource ds, int itemId, String uid) throws ServiceException
/*    */   {
/* 46 */     super(ds, ds.getFolderId(), itemId, uid);
/*    */   }
/*    */   
/*    */   public static Set<PopMessage> getMappings(DataSource ds, String[] remoteIds) throws ServiceException
/*    */   {
/* 51 */     Collection<DbDataSource.DataSourceItem> mappings = DbDataSource.getReverseMappings(ds, Arrays.asList(remoteIds));
/*    */     
/* 53 */     Set<PopMessage> matchingMsgs = new HashSet();
/*    */     
/* 55 */     if (mappings.isEmpty()) {
/* 56 */       Map<Integer, String> oldMappings = DbPop3Message.getMappings(DataSourceManager.getInstance().getMailbox(ds), ds.getId());
/*    */       
/*    */ 
/* 59 */       for (Integer itemId : oldMappings.keySet()) {
/* 60 */         String uid = (String)oldMappings.get(itemId);
/* 61 */         PopMessage mapping = new PopMessage(ds, itemId.intValue(), uid);
/*    */         
/* 63 */         mapping.add();
/* 64 */         for (String remoteId : remoteIds) {
/* 65 */           if (remoteId.equals(uid))
/* 66 */             matchingMsgs.add(mapping);
/*    */         }
/*    */       }
/* 69 */       if (!oldMappings.isEmpty())
/* 70 */         DbPop3Message.deleteUids(DataSourceManager.getInstance().getMailbox(ds), ds.getName());
/*    */     } else {
/* 72 */       for (DbDataSource.DataSourceItem mapping : mappings)
/* 73 */         matchingMsgs.add(new PopMessage(ds, mapping));
/*    */     }
/* 75 */     return matchingMsgs;
/*    */   }
/*    */   
/*    */   public static Set<String> getMatchingUids(DataSource ds, String[] remoteIds) throws ServiceException
/*    */   {
/* 80 */     Set<PopMessage> matchingMsgs = getMappings(ds, remoteIds);
/* 81 */     Set<String> matchingUids = new HashSet(matchingMsgs.size());
/*    */     
/* 83 */     for (PopMessage msg : matchingMsgs)
/* 84 */       matchingUids.add(msg.getRemoteId());
/* 85 */     return matchingUids;
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/datasource/PopMessage.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */